from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup
import sys

def getBs(url):
    try:
        html = urlopen(url)
    except HTTPError as e:
        print(e)
        return None
    try:
        bsObject = BeautifulSoup(html, "html.parser")
    except AttributeError as e:
        return None
    return bsObject

bsObj = getBs("http://en.wikipedia.org/wiki/Kevin_Bacon")
# 所有以“a”开头的
for link in bsObj.findAll("img"):
    if "src" in link.attrs:
        print(link.attrs['src'])
